import fetch from 'common/src/utils/fetch'

/**
 * 校内专业列表
 */
export function findCampusProfessionList(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/findCampusProfessionList',
        method: 'POST',
        data
    })
}

/**
 * 新增
 */
export function addCampusPro(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/addCampusProfession',
        method: 'POST',
        data
    })
}

/**
 * 修改
 */
export function updateCampusPro(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/editCampusProfession',
        method: 'POST',
        data
    })
}

/**
 * 根据ID查校内专业
 */
export function findCampusProById(id) {
    return fetch({
        url: '/api/commonservice/campusProfession/findCampusProfessionById?id=' + id,
        method: 'GET'
    })
}

/**
 * 删除
 */
export function delCampusProById(ids) {
    return fetch({
        url: '/api/commonservice/campusProfession/deleteCampusProfession?ids='+ids,
    })
}

/**
 * 筛选复制
 */
export function copyCampusPro(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/copyCampusProfession',
        method: 'POST',
        data
    })
}

/**
 * 查询大小类校内专业
 */
export function findProByParam(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/findProfessionByParam',
        method: 'POST',
        data
    })
}
/**
 *根据专业查询专业大类
 */
export function findBigProByParam(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/findBigProfessionByParam',
        method: 'POST',
        data
    })
}

/**
 * 导出
 */
export function exportCampusPro(params) {
    let url = '/api/commonservice/campusProfession/findCampusProfessionExport'
    let queryParam = ''
    for (let key in params) {
        // 去掉空参数
        if (key === 'pageNum_' || key === 'pageSize_' || key === 'total_' || params[key] === '') {
            continue
        }
        queryParam += `${key}=${params[key]}&`
    }
    console.log(queryParam)
    window.open(`${url}?${queryParam}`)
}

/* 方向 */

/**
 *新增方向
 */
export function addDirMainten(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/addDirectionMainten',
        method: 'POST',
        data
    })
}

/**
 *编辑方向
 */
export function editDirMainten(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/editDirectionMainten',
        method: 'POST',
        data
    })
}

/**
 *查询方向列表
 */
export function findDirMaintenList(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/findDirectionMaintenList',
        method: 'POST',
        data
    })
}

/**
 *查询专业详情
 */
export function findDirMaintenDetail(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/findDirectionMaintenDetail',
        method: 'POST',
        data
    })
}
/**
 *根据年级专业查方向
 */
export function findDirMaintenByPro(data) {
    return fetch({
        url: '/api/commonservice/directionMainten/findDirectionMaintenByProfession',
        method: 'POST',
        data
    })
}
/**
 * 导出  ?grade=2018&professionCode=10014&keyWord=aaa
 */
export function exportDirMainten(params) {
    let url = '/api/commonservice/directionMainten/findDirectionMaintenExport'
    let queryParam = ''
    for (let key in params) {
        // 去掉空参数
        if (key === 'pageNum_' || key === 'pageSize_' || key === 'total_' || params[key] === '') {
            continue
        }
        queryParam += `${key}=${params[key]}&`
    }
    console.log(queryParam)
    window.open(`${url}?${queryParam}`)
}

/* 校内专业和教育部专业关联查询 *

/**
 *根据年级专业查方向
 */
export function findCampusMinistryRel(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/findCampusMinistryRel',
        method: 'POST',
        data
    })
}
/** ?grade=2018&bigCategory=54001&faculty=000054&category=&professionClassCode=&categoryCode=01&keyWord=2
 *根据年级专业查方向
 */
/**
 * 导出校内专业和教育部专业关系
 */
export function campusMinistryRelExport(params) {
    let url = '/api/commonservice/campusProfession/findCampusMinistryRelExport'
    let queryParam = ''
    for (let key in params) {
        // 去掉空参数
        if (key === 'pageNum_' || key === 'pageSize_' || key === 'total_' || params[key] === '') {
            continue
        }
        queryParam += `${key}=${params[key]}&`
    }
    console.log(queryParam)
    window.open(`${url}?${queryParam}`)
}

/**
 *删除专业方向 逻辑删除
 */
export function logicalDelDirection(grade, professionCode, code) {
    return fetch({
        url:
            '/api/commonservice/directionMainten/logicalDelDirection?grade=' +
            grade +
            '&professionCode=' +
            professionCode +
            '&code=' +
            code,
        method: 'get'
    })
}
/**
 * 判断专业是否可以删除
 * @param {*} grade 年级
 * @param {*} major 专业Code
 * @param {*} directionCode  方向Code
 */
export function checkDirection(grade, major, directionCode) {
    return fetch({
        url: `/api/cultureservice/bclCultureScheme/checkDirection?grade=${grade}&major=${major}&directionCode=${directionCode}`,
        method: 'GET'
    })
}

/**
 * 自动获取专业/方向code
 * @param {*} type 类型，1时为专业，2时为方向
 * @param {*} prex 前置code
 * @param {*} grade 年级，当type为1时必须填写
 */
export function getCode(type, prex, grade) {
    return fetch({
        url: `/api/commonservice/campusProfession/code?type=${type}&&prex=${prex}&&grade=${grade}`
    })
}


/**
 * 批量修改
 */
export function updateBatchCampusPro(data) {
    return fetch({
        url: '/api/commonservice/campusProfession/editBatchCampusProfession',
        method: 'POST',
        data
    })
}